<!--title={MAIN};css=zui.min;js=zui.min;-->
{nav}
<div class="container-fluid">
    <ol class="breadcrumb">
        <li><a href="./?/"><i class="icon-home"></i> {TEXT_HOME}</a></li>
        <li class="active">{TEXT_MAIN}</li>
    </ol>
</div>
<div class="text-center bg-primary container-fluid">
    <h1 id="room-name" data-toggle="tooltip" data-placement="bottom" title="XCID：{getRoomXCID()}"><b id="room-name-text"></b><b title="{ROOM_NAME_EDIT}" data-toggle="tooltip" id="room-name-edit-bar"><button id="room-name-edit" style="display: none" class="btn btn-primary" onclick="show_edit_name_input_bar();"><i class="icon-edit"></i></button></b></h1>
    <b id="room-name-edit-input-bar" style="display: none"><label for="room-name-edit-input">{ROOM_NAME_EDIT_LABEL}</label><input class="input-control" id="room-name-edit-input" type="text"><button class="btn btn-primary" data-toggle="tooltip" title="{SAVE}"><i class="icon-check-circle icon-2x" onclick="save_room_name();"></i></button><button class="btn btn-primary" data-toggle="tooltip" title="{CANCEL}" onclick="hide_edit_name_input_bar();"><i class="icon-remove-sign icon-2x"></i></button></b>
    <h3 id="room-description"><b id="room-description-text"></b><b title="{ROOM_DESCRIPTION_EDIT}" data-toggle="tooltip" id="room-description-edit-bar"><button id="room-description-edit" style="display: none" class="btn btn-primary btn-sm" onclick="show_edit_description_input_bar()"><i class="icon-edit"></i></button></b></h3>
    <b id="room-description-edit-input-bar" style="display: none"><label for="room-description-edit-input">{ROOM_NAME_EDIT_LABEL}</label><input class="input-control" id="room-description-edit-input" type="text"><button class="btn btn-primary" data-toggle="tooltip" title="{SAVE}"><i class="icon-check-circle icon-2x" onclick="save_room_description();"></i></button><button class="btn btn-primary" data-toggle="tooltip" title="{CANCEL}" onclick="hide_edit_description_input_bar();"><i class="icon-remove-sign icon-2x"></i></button></b>
    <h5 class="small">{TEXT_CREATOR} : <b id="room-creator"></b></h5>
    <h5 class="small">{TEXT_CREATE_TIME} : <b id="room-create-time"></b></h5>
    <div class="btn-group">
        <button type="button" class="btn btn-info btn-lg dropdown-toggle"
                data-toggle="dropdown">{TEXT_SEND_MESSAGE}  <span class="caret"></span></button>
        <ul class="dropdown-menu text-left" role="menu">
            <li class="dropdown-header">{TEXT_MESSAGE_TYPE}</li>
            <li><a href="javascript:;" onclick="snt();">{TEXT_NORMAL_TEXT}</a></li>
            <li><a href="javascript:;" onclick="shl();">{TEXT_HYPERLINK}</a></li>
            <li><a href="javascript:;" onclick="sph();">{TEXT_PHOTO}</a></li>
            <li><a href="javascript:;" onclick="sfi();">{TEXT_FILE}</a></li>
            <li class="divider"></li>
            <li><a href="javascript:;">{TEXT_CANCEL}</a></li>
        </ul>
    </div>
    <button class="btn btn-info btn-lg" data-toggle="tooltip" title="{TEXT_RELOAD_MESSAGE}" id="reload-message">
        <b class="icon-refresh"></b></button>
    <br><br>
</div>
<div id="root-comment-list" class="container load-indicator">

</div>
<div style="display: none" id="temp-comment-list"></div>
<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="modal-title"></h4>
            </div>
            <div class="modal-body">
                <p id="modal-body"></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="modal-button-cancel"></button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade load-indicator" data-loading="{SENDING}" id="nt-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="nt-modal-title">{SEND_NORMAL_TEXT}</h4>
            </div>
            <div class="modal-body">
                <label for="nt-message">{MESSAGE_CONTENT}:</label>
                <textarea name="nt-message" id="nt-message" cols="30" rows="10" class="form-control"
                          placeholder="{MESSAGE_CONTENT}" style="width: 100%;height: 300px;"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"
                        id="nt-modal-button-cancel">{CANCEL}</button>
                <button type="button" class="btn btn-primary" onclick="snt_p();">{SEND}</button>
            </div>
        </div>
    </div>
</div><!-- 发送普通文字对话框 -->
<div class="modal fade load-indicator" data-loading="{SENDING}" id="hl-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="hl-modal-title">{SEND_HYPER_LINK}</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="hl-name">{SEND_HYPER_LINK_NAME}</label>
                    <input type="text" class="form-control" id="hl-name" placeholder="{SEND_HYPER_LINK_NAME}">
                </div>
                <div class="form-group">
                    <label for="hl-link">{SEND_HYPER_LINK_CONTENT}</label>
                    <input type="text" class="form-control" id="hl-link" placeholder="{SEND_HYPER_LINK_CONTENT}">
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal"
                    id="hl-modal-button-cancel">{CANCEL}</button>
            <button type="button" class="btn btn-primary" onclick="shl_p();">{SEND}</button>
        </div>
    </div>
</div><!-- 发送超链接对话框 -->
<div class="modal fade load-indicator" data-loading="{REPLYING}" id="rpl-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="rpl-modal-title">{REPLY}</h4>
            </div>
            <p style="display: none" id="rpl-id"></p>
            <p style="display: none" id="rpl-name"></p>
            <p style="display: none" id="rpl-user"></p>
            <div class="modal-body">
                <label for="rpl-message">{REPLY_CONTENT}:</label>
                <textarea name="rpl-message" id="rpl-message" cols="30" rows="10" class="form-control"
                          placeholder="{REPLY_CONTENT}"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"
                        id="rpl-modal-button-cancel">{CANCEL}</button>
                <button type="button" class="btn btn-primary" onclick="rpl_p();">{REPLY}</button>
            </div>
        </div>
    </div>
</div><!-- 回复对话框 -->
<div class="modal fade load-indicator" data-loading="{DELETING}" id="del-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="del-modal-title">{DELETE}</h4>
            </div>
            <p id="delete_message_id" style="display: none"></p>
            <div class="modal-body">
                <p>{DELETE_DIALOG_BODY}</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"
                        id="del-modal-button-cancel">{CANCEL}</button>
                <button type="button" class="btn btn-primary"
                        onclick="delete_message_p();">{DELETE}</button>
            </div>
        </div>
    </div>
</div><!-- 删除对话框 -->
<div class="modal fade load-indicator" data-loading="{CHANGING}" id="edit-nt-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="edit-nt-modal-title">{EDIT}</h4>
            </div>
            <p id="edit-nt-message-id" style="display: none"></p>
            <div class="modal-body">
                <label for="edit-nt-message">{MESSAGE_CONTENT}:</label>
                <textarea name="edit-nt-message" id="edit-nt-message" cols="30" rows="10" class="form-control"
                          placeholder="{MESSAGE_CONTENT}" style="width: 100%;height: 300px;" autofocus="autofocus"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"
                        id="edit-modal-button-cancel">{CANCEL}</button>
                <button type="button" class="btn btn-primary"
                        onclick="edit_nt();">{SAVE_CHANGE}</button>
            </div>
        </div>
    </div>
</div><!-- 编辑普通文字对话框 -->
<div class="modal fade load-indicator" data-loading="{CHANGING}" id="edit-hl-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                        class="sr-only">{CLOSE}</span></button>
                <h4 class="modal-title" id="edit-hl-modal-title">{EDIT}</h4>
            </div>
            <p style="display: none" id="edit-hl-id"></p>
            <div class="modal-body">
                <div class="form-group">
                    <label for="edit-hl-name">{SEND_HYPER_LINK_NAME}</label>
                    <input type="text" class="form-control" id="edit-hl-name" placeholder="{SEND_HYPER_LINK_NAME}">
                </div>
                <div class="form-group">
                    <label for="edit-hl-link">{SEND_HYPER_LINK_CONTENT}</label>
                    <input type="text" class="form-control" id="edit-hl-link" placeholder="{SEND_HYPER_LINK_CONTENT}">
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal"
                    id="edit-hl-modal-button-cancel">{CANCEL}</button>
            <button type="button" class="btn btn-primary" onclick="edit_hl();">{SAVE_CHANGE}</button>
        </div>
    </div>
</div><!-- 编辑超链接对话框 -->
<script>
    var message_load_counter_code = 0;
    // KindEditor.ready(function(K) {
    //     window.editor = K.create('#nt-message');
    // });
    setInterval(function () {
        $.post("./?/getMessageLoadCounter",{},function (data) {
            if (data!==message_load_counter_code){
                /*new $.zui.Messager("{GOT_NEW_MESSAGE}",{
                    type:"info",
                    close:false,
                    time:0,
                    actions:[{
                        name:"reload",
                        icon:"refresh",
                        text:"{RELOAD}",
                        action:function () {
                            reloadMessage();
                        }
                    }]
                }).show();*/
                reloadMessage();
                message_load_counter_code=data;
            }
        })
    },100);
    $("#room-name").mouseover(function () {
        // console.log("on");
        $("#room-name-edit").show();
    }).mouseout(function () {
        // console.log("out");
        $("#room-name-edit").hide();
    });
    $("#room-description").mouseover(function () {
        $("#room-description-edit").show();
    }).mouseout(function () {
       $("#room-description-edit").hide();
    });
    $('[data-toggle="tooltip"]').tooltip();
    DELETE = "{DELETE}";
    REPLY = "{REPLY}";
    EDIT = "{EDIT}";
    ROOM_XCID = "{getRoomXCID()}";
    var room_creator;
    reloadMessage();
    $("#reload-message").click(function () {
        reloadMessage();
    });

    function addMessage(user, name, content, time, replyName, replyUser, replyXCID, xcid, dz_counter, dz_ed, canEdit,type,data) {
        var message_id = xcid;
        var message_reply_action_xcid = replyXCID === "root" ? xcid : replyXCID;
        var message_dz_ed = dz_ed ? "text-primary" : "";
        var message_dz_counter = dz_counter;
        var message_dz_button_id = xcid + "-dz-button";
        var message_dz_counter_id = xcid + "-dz-counter";
        var message_comment_list = replyUser === "root" ? "<div id='" + xcid + "-comment-list' class='comments-list collapse'></div>" : "";
        var message_reply = replyUser === "root" ? "" : " <span class=\"text-muted\">{REPLY}</span> <a href=\"javascript:;\" class='btn btn-link'>" + replyName + "</a>";
        var message_canEdit = canEdit ? "<a href='javascript:;' onclick=\"edit('" + xcid + "')\" class='btn btn-link'>{EDIT}</a><a href='javascript:;' onclick=\"delete_message('" + xcid + "')\" class='btn btn-link'>{DELETE}</a>" : "";
        var message_replyXCID = replyXCID === "root" ? xcid : xcid;
        var message_reply_list_button = replyXCID === "root" ? '<a id="' + xcid + '-rlb" href="#' + xcid + '-comment-list" class="btn btn-link" data-toggle="collapse" style="display: none">{REPLY_LIST} <b class="caret"></b></a>' : "";
        var v1 = '<div class="comment" id="' + message_id + '"><a style="display: none" id="'+message_id+'-type">'+type+'</a><a style="display: none" id="'+message_id+'-data">'+data+'</a><a href="javascript:;" class="avatar"><i class="icon-user icon-2x btn btn-link"></i></a><div class="content"><div class="pull-right text-muted xc_message">' + time + '</div><div><a href="javascript:;" class="btn btn-link"><strong>' + name + '</strong></a>' + message_reply + '</div><div class="text xc_message"><pre id="'+xcid+'-content">' + content + '</pre></div><div class="actions"><a href="javascript:;" onclick="reply(\'' + message_reply_action_xcid + '\',\'' + user + '\',\'' + name + '\')" class="btn btn-link">{REPLY}</a>' + message_canEdit + message_reply_list_button + '<a href="javascript:;" onclick="dz(\'' + message_replyXCID + '\')" class="pull-right btn btn-link"><b id="' + message_dz_button_id + '" class="icon-thumbs-up ' + message_dz_ed + '"> <b id="' + message_dz_counter_id + '">' + message_dz_counter + '</b></b></a></div></div>' + message_comment_list + '</div>'
        if (replyXCID !== "root") {
            var rlpID = "#" + replyXCID + "-rlb";
            $(rlpID).show();
        }
        var reply_comment_id = replyUser === "root" ? "root-comment-list" : replyXCID + "-comment-list";
        $("#temp-comment-list").append(v1);
        document.getElementById(reply_comment_id).appendChild(document.getElementById(xcid));
    }

    function getRoomInfo() {
        $.post("./?/getRoomInfo", {"xcid": ROOM_XCID}, function (text) {
            // console.log(text);
            // return;
            if (text === "database-error") {
                console.log("load room info error");
                myModal("{TIP}", "{DATABASE_ERROR}", "{CLOSE}");
            } else {
                var data = JSON.parse(text);
                $("#room-name-text").text(data.name);//.attr({"data-original-title": "XCID ：" + data.xcid});
                $("#room-description-text").text(data.description);
                $("#room-creator").text(data.creator!==data.creator_name?(data.creator_name+"("+data.creator+")"):data.creator);
                $("#room-create-time").text(data.create_time);
                room_creator = data.creator;
                if ("{DATA_isAdmin}" !== "yes" && room_creator !== "{DATA_username}"){
                    $("#room-name-edit-bar").text("");
                    $("#room-description-edit-bar").text("");
                }
            }
            $("#root-comment-list").removeClass("loading").attr({"data-loading": "读取聊天数据中..."}).addClass("loading");
        });
    }

    function getMessageList() {
        $.post("./?/getMessageList", {"xcid": ROOM_XCID}, function (data) {
            // alert(data);
            if (data === "database-error") {
                console.log("load message error");
                myModal("{TIP}", "{DATABASE_ERROR}", "{CLOSE}");
            } else {
                var list = JSON.parse(data);
                // console.log(list);
                for (x in list) {
                    var temp_list = JSON.parse(list[x]);
                    message_load_counter_code = temp_list["message_load_counter_code"];
                    // console.log(temp_list);
                    addMessage(temp_list['user'], temp_list['name'], temp_list['content'], temp_list['time'], temp_list['reply_name'], temp_list['reply_user'], temp_list['reply_id'], temp_list['id'], temp_list['dz_counter'], temp_list['dz_ed'], temp_list['canEdit'],temp_list['type'],temp_list['data']);
                }
            }
            $("#root-comment-list").removeClass("loading");
        });
    }

    function myModal(title, body, button1) {
        document.getElementById("modal-title").innerText = title;
        document.getElementById("modal-body").innerHTML = body;
        document.getElementById("modal-button-cancel").innerText = button1;
        $("#myModal").modal();
    }

    function show_edit_name_input_bar() {
        $("#room-name-edit-input-bar").show();
        $("#room-name").hide();
        $("#room-name-edit-bar").hide();
        document.getElementById("room-name-edit-input").value = $("#room-name-text").text();
    }
    function hide_edit_name_input_bar() {
        $("#room-name-edit-input-bar").hide();
        $("#room-name").show();
        $("#room-name-edit-bar").show();
        document.getElementById("room-name-edit-input").value = "";
    }
    function save_room_name() {
        var new_name = document.getElementById("room-name-edit-input").value;
        $.post("./?/saveRoomName",{xcid:ROOM_XCID,new_name:new_name},function (text) {
            var list = JSON.parse(text);
            switch (list.status) {
                case "database-error":
                    console.log("数据库错误");
                    console.log(list.reason);
                    myModal("{TIP}","{DATABASE_ERROR}","{CLOSE}");
                    hide_edit_name_input_bar();
                    break;
                case "successful":
                    hide_edit_name_input_bar();
                    getRoomInfo();
                    setTimeout(function () {
                        $("#root-comment-list").removeClass("loading");
                    },1000);
                    break;
            }
        });
        
    }
    function show_edit_description_input_bar() {
        $("#room-description-edit-input-bar").show();
        $("#room-description").hide();
        $("#room-description-edit-bar").hide();
        document.getElementById("room-description-edit-input").value = $("#room-description-text").text();
    }
    function hide_edit_description_input_bar() {
        $("#room-description-edit-input-bar").hide();
        $("#room-description").show();
        $("#room-description-edit-bar").show();
        document.getElementById("room-description-edit-input").value = "";
    }
    function save_room_description() {
        var new_desc = document.getElementById("room-description-edit-input").value;
        $.post("./?/saveRoomDescription",{xcid:ROOM_XCID,new_desc:new_desc},function (text) {
            var list = JSON.parse(text);
            switch (list.status) {
                case "database-error":
                    console.log("数据库错误");
                    console.log(list.reason);
                    myModal("{TIP}","{DATABASE_ERROR}","{CLOSE}");
                    hide_edit_description_input_bar();
                    break;
                case "successful":
                    hide_edit_description_input_bar();
                    getRoomInfo();
                    setTimeout(function () {
                        $("#root-comment-list").removeClass("loading");
                    },1000);
                    break;
            }
        })
    }

    function dz(id) {
        // alert("点赞功能维护中");
        // return;
        var dz_id = "#" + id + "-dz-counter";
        var dz_ed_id = "#" + id + "-dz-button";
        if ($(dz_ed_id).hasClass("text-primary")) {
            $(dz_id).text($(dz_id).text() - 1);
            $(dz_ed_id).removeClass("text-primary");
        } else {
            $(dz_id).text(Number($(dz_id).text()) + 1);
            $(dz_ed_id).addClass("text-primary");
        }
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                var text = xmlhttp.responseText;
                var list = JSON.parse(text);
                switch (list['status']) {
                    case "successful":
                        $(dz_id).text(list['data']);
                        if (list['dz_ed']) {
                            $(dz_ed_id).addClass("text-primary");
                        } else {
                            $(dz_ed_id).removeClass("text-primary");
                        }
                        
                        break;
                    case "error":
                        console.log(list['reason']);
                        break;
                    case "database-error":
                        myModal("{TIP}", "{DATABASE_ERROR}", "{CLOSE}");
                        console.log(list['reason']);
                        break;
                    default:
                        console.log("未定义的返回数据：" + list);
                        break;
                }
            }
        };
        xmlhttp.open("POST", "./?/dz", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("id=" + id);

    }

    // 发送留言
    function snt() {//普通文本
        $(document).ready(function () {
            $("#nt-modal").modal();
        });
    }

    function snt_p() {//普通文本发送处理
        $(document).ready(function () {
            $("#nt-modal").addClass("loading");
            text = document.getElementById("nt-message").value;
            if (text === "") {
                myModal("{TIP}", "{MESSAGE_EMPTY}", "{CLOSE}");
            } else {
                var xmlhttp;
                if (window.XMLHttpRequest) {
                    xmlhttp = new XMLHttpRequest();
                } else {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                        var text = xmlhttp.responseText;
                        $("#nt-modal").removeClass("loading");
                        document.getElementById("nt-message").value = "";
                        if (text === "database-error") {
                            myModal("{TIP}", "{DATABASE_ERROR}", "{CLOSE}");
                        } else if (text === "send-successful") {
                            myModal("{TIP}", "{SEND_SUCCESSFUL}", "{CLOSE}");
                            
                            setTimeout(function () {
                                self.window.location = "./?/main";
                            }, 1000);
                        }
                    }
                };
                xmlhttp.open("POST", "./?/snt", true);
                xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlhttp.send("content=" + text);
                $("#nt-modal").modal('toggle');
            }
        });
    }

    function reply(id, user, name) {
        $(document).ready(function () {
            $("#rpl-modal").modal();

            document.getElementById("rpl-id").innerText = id;
            // document.getElementById("rpl-name").innerText = name;
            document.getElementById("rpl-user").innerText = user;
            document.getElementById("rpl-modal-title").innerText = "{REPLY} " + name;

        })
    }

    function rpl_p() {
        rpl_content = document.getElementById("rpl-message").value;
        rpl_id = document.getElementById("rpl-id").innerText;
        rpl_name = document.getElementById("rpl-name").innerText;
        rpl_user = document.getElementById("rpl-user").innerText;
        if (rpl_content === "") {
            myModal("{TIP}", "{MESSAGE_EMPTY}", "{CLOSE}");
        } else {
            var xmlhttp;
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest();
            } else {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                    text = xmlhttp.responseText;
                    $("#nt-modal").removeClass("loading");
                    document.getElementById("nt-message").value = "";
                    if (text === "database-error") {
                        myModal("{TIP}", "{DATABASE_ERROR}", "{CLOSE}");
                    } else if (text === "send-successful") {
                        myModal("{TIP}", "{REPLY_SUCCESSFUL}", "{CLOSE}");

                        setTimeout(function () {
                            self.window.location = "./?/main";
                        }, 1000);
                    } else {
                        // myModal("{TIP}","0" + text,"{CLOSE}");
                    }
                }
            };
            $("#rpl-modal").modal('toggle');
            xmlhttp.open("POST", "./?/snt", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("content=" + rpl_content + "&replyXCID=" + rpl_id + "&replyUser=" + rpl_user);
        }
    }

    function shl() {//超链接
        $(document).ready(function () {
            $("#hl-modal").modal();
        });
    }

    function shl_p() {
        var link = document.getElementById("hl-link").value;
        var name = document.getElementById("hl-name").value;
        $("#hl-modal").addClass("loading");
        $.post("./?/shl",{
            link:link,
            name:name
        },function (data) {
            var value = JSON.parse(data);
            $("#hl-modal").removeClass("loading").modal("toggle");
            if (value.status === "success"){
                myModal("{TIP}","{SEND_SUCCESSFUL}","{CLOSE}");

                setTimeout(function () {
                    self.window.location = "./?/main";
                },1000);
            }else if (value.status === "fail"){
                myModal("{TIP}","{DATABASE_ERROR}","{CLOSE}");
                console.log(value.reason);
            }
        })
    }

    function sph() {//图片

    }

    function sfi() {//文件

    }

    function edit(id) {
        switch ($("#"+id+"-type").text()) {
            case "NORMAL_TEXT":
                $("#edit-nt-modal").modal();
                $("#edit-nt-message-id").text(id);
                $("#edit-nt-message").text($("#"+id+"-content").text());
                break;
            case "HYPER_LINK":
                $("#edit-hl-modal").modal();
                $("#edit-hl-id").text(id);
                document.getElementById("edit-hl-link").value = $("#"+id+"-data").text();
                document.getElementById("edit-hl-name").value = $("#"+id+"-content").text();
                break;
        }
        // $("#edit-modal").modal();
        // $("#edit_message_id").text(id);
        // $("#edit-message").text($("#"+id+"-content").text().replace("<br>","\n"));

    }

    function edit_nt() {
        $("#edit-nt-modal").addClass("loading");
        var id = $("#edit-nt-message-id").text();
        var content = document.getElementById("edit-nt-message").value;
        $.post("./?/editMessage",{id:id,content:content},function (text) {
            $("#edit-nt-modal").removeClass("loading").modal("toggle");
            var data = JSON.parse(text);
            switch (data.status) {
                case "successful":
                    console.log("成功");
                    $("#"+data.xcid+"-content").text(data.content);
                    myModal("{TIP}","{EDIT_MESSAGE_SUCCESSFUL}","{CLOSE}");
                    setTimeout(function () {
                        $("#myModal").modal("toggle");
                    },1000);
                    break;
                case "database-error":
                    console.log("数据库错误");
                    console.log(data.reason);
                    myModal("{TIP}","{DATABASE_ERROR}","{CLOSE}");
                    break;
            }
        })
    }

    function edit_hl() {
        $("#edit-hl-modal").addClass("loading");
        var id = $("#edit-hl-id").text();
        var name = document.getElementById("edit-hl-name").value;
        var link = document.getElementById("edit-hl-link").value;
        $.post("./?/editHyperLink",{
            id:id,
            name:name,
            link:link
        },function (data) {
            var value = JSON.parse(data);
            $("#edit-hl-modal").removeClass("loading").modal("toggle");
            if(value.status==="successful"){
                myModal("{TIP}","{EDIT_MESSAGE_SUCCESSFUL}","{CLOSE}");
                setTimeout(function () {
                    $("#myModal").modal("toggle");
                },1000);
            }else if (value.status==="database-error"){
                myModal("{TIP}","{DATABASE_ERROR}","{CLOSE}");
            }
        });
    }

    function delete_message(id) {
        $("#del-modal").modal();
        document.getElementById("delete_message_id").innerText = id;
    }

    function delete_message_p() {
        $("#del-modal").addClass("loading");
        id = document.getElementById("delete_message_id").innerText;
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                text = xmlhttp.responseText;
                $("#del-modal").removeClass("loading");
                if (text === "database-error") {
                    myModal("{TIP}", "{DATABASE_ERROR}", "{CLOSE}");
                } else if (text === "message-not-exist") {
                    myModal("{TIP}", "{MESSAGE_NOT_EXIST}", "{CLOSE}");
                } else if (text === "delete-successful") {
                    myModal("{TIP}", "{DELETE_SUCCESSFUL}", "{CLOSE}");
                    setTimeout(function () {
                        self.window.location = "./?/main";
                    }, 1000);
                } else {
                    myModal("{TIP}", text, "{CLOSE}");
                }
            }
        };
        $("#del-modal").modal('toggle');
        xmlhttp.open("POST", "./?/del", true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send("id=" + id);
    }

    function cleanComment() {
        document.getElementById("root-comment-list").innerText = "";
        document.getElementById("temp-comment-list").innerText = "";
    }

    function reloadMessage() {
        cleanComment();
        $("#root-comment-list").attr({"data-loading": "读取房间数据中..."}).addClass("loading");
        getRoomInfo();
        getMessageList();
        setTimeout(function () {
            $("#root-comment-list").removeClass("loading");
        },1000);
    }
</script>
</body>